package com.nnxy.worktostudy.security.entity;

import com.nnxy.worktostudy.system.entity.Admin;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

/**
 * @Author : lu'qz
 * @create 2021/9/22 18:35
 */
@Data
public class SecurityUser implements UserDetails {
    //当前登录用户
    private transient Admin currentUserInfo;

    private List<String> permissionValueList;

    public SecurityUser() {
    }

    public SecurityUser(Admin admin) {
        if (admin != null) {
            this.currentUserInfo = admin;
        }
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    @Override
    public String getPassword() {
        return currentUserInfo.getPassword();
    }

    @Override
    public String getUsername() {
        return currentUserInfo.getUsername();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return currentUserInfo.getStatus();
    }
}
